package cate.game.play.skill.passive.furniture;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 攻击时恢复自身敌方当前生命值的15%，每回合最多2次；自身生命值低于30%时该效果提升至20%，单次恢复不超过最大生命值的15%
 */
public class 伤口盛宴PH extends PassiveHandler {

	private double 恢复系数;
	private int 次数;

	private int 检测血量;
	private double 强化系数;
	private double 最大系数;

	//恢复系数=1500&次数=2&
	//检测血量=3000&强化系数=2000&最大系数=1500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		恢复系数 = args.getWDouble("恢复系数", 0d);
		次数 = args.getInt("次数", 0);

		检测血量 = args.getInt("检测血量", 0);
		强化系数 = args.getWDouble("强化系数", 0d);
		最大系数 = args.getWDouble("最大系数", 0d);
	}


	@Override
	public void onRoundBegin(ActionCtx action) {
		healTime = 0;
	}

	private int healTime;

	@Override
	public void afterOneAttack(SkillActionCtx action, long totalDamage, boolean strike, Fighter target) {
		if (healTime >= 次数) {
			return;
		}
		double healRate = skill.owner.attr.total().hpCurRate() >= 检测血量 ? 恢复系数 : 强化系数;
		double value = target.attr.total().hpCur() * healRate;
		value = Math.min(value, skill.owner.attr.total().hpTotal() * 最大系数);
		if (value > 0) {
			skill.owner.attr.passiveHeal(action, value);
			healTime++;
		}
	}
}
